package com.xin.auto.lib.base;

import android.util.Log;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

public class CalendarUtils {
    private static final String TAG = "CalendarUtils";

    public static String getYear() {
        Calendar cal = Calendar.getInstance();
        return String.valueOf(cal.get(Calendar.YEAR));
    }

    public static int getMonth() {
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.MONTH) + 1;
    }

    public static int get12OutMonth() {
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.MONTH) + 1;
    }

    public static boolean isOClock() {
        Calendar cal = Calendar.getInstance();
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        return minute == 0 && second == 0;
    }

    /**
     * 0点0分
     *
     * @return
     */
    public static boolean isOClockO() {
        Calendar cal = Calendar.getInstance();
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        Log.d(TAG, "hour: " + hour + ", minute:" + minute + ", second: " + second);
        return minute == 0 && hour == 0 && second < 7;
    }

    public static void saveTask(int month, int value) {
        Calendar cal = Calendar.getInstance();
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        boolean minute = cal.get(Calendar.MINUTE) < 1;
        boolean second = cal.get(Calendar.SECOND) < 10;
        if (hour == 20 && minute && second) {
            Timer timer = new Timer();//新建Timer类
            timer.schedule(new TimerTask() {//每天执行输出时间
                @Override
                public void run() {

                }
            }, cal.getTime(), 24 * 60 * 60 * 1000);
        }
    }
}
